package com.ww.editsms.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chinawangw.R;
import com.ww.editsms.entity.Person;
import com.ww.editsms.util.SmsUtil;


public class PersonAdapter extends BaseAdapter {

	Context context;
	List<Person> list;
	LayoutInflater lif;

	public PersonAdapter(Context context, List<Person> list) {
		this.context = context;
		this.list = list;
	}
	
	

	public List<Person> getList() {
		return list;
	}



	public void setList(List<Person> list) {
		this.list = list;
	}



	public int getCount() {
		return list.size();
	}

	public Object getItem(int position) {
		return null;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {
		final MyView mv;
		if (convertView == null) {
			mv = new MyView();
			lif = LayoutInflater.from(context);// 转化到context这个容器
			convertView = lif.inflate(R.layout.personitem, null);// 设置要转化的layout文件
		} else {
			mv = (MyView) convertView.getTag();
		}
		mv.img = (ImageView) convertView.findViewById(R.id.image);// 取得实例
		mv.tv1 = (TextView) convertView.findViewById(R.id.name);// 取得实例
		mv.tv3 = (TextView) convertView.findViewById(R.id.time);// 取得实例
		mv.tv4 = (TextView) convertView.findViewById(R.id.desc);// 取得实例
		if(list.get(position).getPhoto()!=null){
		mv.img.setImageBitmap(list.get(position).getPhoto());
		}
		mv.img.setPadding(5, 5, 5, 5);
		if (list.get(position).getName() == null) {
			mv.tv1.setText((position+1)+"      "+list.get(position).getNumber());
		} else {
			mv.tv1.setText((position+1)+"      "+list.get(position).getName());
		}
		mv.tv3.setText(SmsUtil.getdays(Long
				.parseLong(list.get(position).getTime())));
		mv.tv4.setText(list.get(position).getDesc());
		convertView.setTag(mv);
		return convertView;
	}
	
	

	private static class MyView {
		ImageView img;
		TextView tv1;
		TextView tv3;
		TextView tv4;

	}
}
